<template>
  <div class="container">
    <div><label>用户名: <input v-model="loginName" type="text"></label></div>
    <div><label>密码: <input v-model="password" type="password"></label></div>
    <button @click="requestLogin">登录</button>
    <div style="color: red">{{ error }}</div>
  </div>
</template>

<script>

export default {
  data() {
    return {
      loginName: '',
      password: '',
      error: ''
    }
  },
  methods: {
    async requestLogin() {
      try {
        await this.$axios.post('http://localhost:8081/login', {
          loginName: this.loginName,
          password: this.password
        })
        this.$router.push('/me')
      } catch (error) {
        this.error = error.response.data.message
      }
    }
  }
}
</script>

<style>
</style>
